<template>
	<view class="container">
		<view class="search-view-container">
			<view class="search-view" @click="goToSearchPlayer()">
				<image class="search-view-icon" src="../../static/images/search@3x.png"></image>
				<input maxlength="50" class="search-view-input" placeholder="请输入教练昵称" disabled="disabled" placeholder-class="placeholder" />
			</view>

			<image class="more-btn" @click="showMoreWrapper" src="../../static/images/cla.png"></image>
		</view>
		<view class="sell-container">
			<view v-if="playerList.length == 0" class="empty"><text>抱歉！没有找到符合条件的教练</text></view>
			<yue-wan v-else class="sell-item" v-for="(item, index) in playerList" :key="index" :itemData="item"></yue-wan>
		</view>
		<view class="more-list-wrapper" v-show="isShowWapper" @click="hideWapper">
			<view class="more-list-view">
				<view class="more-list-view__item top-left-right" @click="clickTypeItem(0)"><text :class="wrapperIndex == 0 ? 'selected-text' : 'normal-text'">全部</text></view>
				<view class="more-list-view__item" @click="clickTypeItem(1)"><text :class="wrapperIndex == 1 ? 'selected-text' : 'normal-text'">男生</text></view>
				<view class="more-list-view__item" @click="clickTypeItem(2)"><text :class="wrapperIndex == 2 ? 'selected-text' : 'normal-text'">女生</text></view>
				<view class="more-list-view__item bottom-left-right" @click="clickTypeItem(3)"><text :class="wrapperIndex == 3 ? 'selected-text' : 'normal-text'">游戏</text></view>
				<view class="arrow"></view>
			</view>
		</view>
		<view class="game-tag-container" v-show="isShowGameTag" @click="clickGameTagContainer">
			<view class="game-tag-container__body">
				<text class="game-tag-container__body-title">游戏</text>
				<view class="game-tag-container__tag">
					<view
						v-for="(item, index) in gameTagList"
						:key="index"
						@click.stop="clickGameTagItem(index)"
						:class="gameTagSelectedList.indexOf(index) != -1 ? 'game-tag-container__item selected-game-tag' : 'game-tag-container__item'"
					>
						{{ item.TagName }}
					</view>
				</view>
				<view class="game-tag-container__bottom">
					<view class="game-tag-container__bottom-reset-btn" @click.stop="resetGameTag">重置</view>
					<view class="game-tag-container__bottom-confirm-btn" @click.stop="confirmGameTag">确定</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { isLogin, toLogin, showShareMenu } from '@/config/common.js';
import yueWan from '../../components/yuewan-item.vue';
import { servePlayerList, getAllTagList } from '../../constant/customer.js';
export default {
	components: {
		yueWan
	},
	data() {
		return {
			playerList: [],
			isShowWapper: false,
			isShowGameTag: false,
			wrapperIndex: 0,
			gameTagSelectedList: [],
			gameTagList: [],
			servePlayType: 1,
			query_filter: {
				gender: '',
				tags: '',
				keyword: '',
				pageIndex: 0,
				pageSize: 10
			}
		};
	},
	onLoad() {
		this.searchPlayerList();
		this.getTagList();
		showShareMenu();
	},
	onReachBottom() {
		this.query_filter.pageIndex++;
		this.searchPlayerList();
	},
	onPullDownRefresh() {
		this.query_filter.pageIndex = 0;
		this.searchPlayerList();
	},
	methods: {
		resetGameTag() {
			this.gameTagSelectedList = [];
		},
		clickGameTagContainer() {
			this.isShowGameTag = false;
		},
		confirmGameTag() {
			let tags = [];
			for (let i = 0; i < this.gameTagSelectedList.length; i++) {
				tags.push(this.gameTagList[this.gameTagSelectedList[i]].TagName);
			}
			this.query_filter.tags = tags.join(',');
			this.clickGameTagContainer();
			this.query_filter.pageIndex = 0;
			this.searchPlayerList(this.query_filter);
		},
		clickGameTagItem(val) {
			let index = this.gameTagSelectedList.indexOf(val);
			if (index == -1) {
				this.gameTagSelectedList.push(val);
			} else {
				this.gameTagSelectedList.splice(index, 1);
			}
		},
		showMoreWrapper() {
			this.isShowWapper = true;
		},
		hideWapper() {
			this.isShowWapper = false;
		},
		clickTypeItem(val) {
			this.wrapperIndex = val;
			if (val == 0) {
				this.query_filter.pageIndex = 0;
				this.query_filter.gender = '';
				this.searchPlayerList();
			} else if (val == 1 || val == 2) {
				this.query_filter.pageIndex = 0;
				this.query_filter.gender = val == 1 ? '男' : '女';
				this.searchPlayerList();
			} else {
				this.isShowGameTag = true;
			}
		},
		async getTagList() {
			let res = await getAllTagList({ ServePlayType: this.servePlayType });
			this.gameTagList = res;
		},
		async searchPlayerList() {
			let res = await servePlayerList(this.query_filter);

			uni.stopPullDownRefresh();
			if (this.query_filter.pageIndex > 0) {
				for (let i = 0; i < res.Source.length; i++) {
					let obj = res.Source[i];
					this.playerList.push(obj);
				}
			} else {
				this.playerList = res.Source;
			}
			//如果查到的数据为空   回到上一页
			if (res.Source.length == 0) {
				this.query_filter.pageIndex--;
			}
		},
		goToSearchPlayer() {
			uni.navigateTo({
				url: './searchplayer/index'
			});
		},
		parentClickPlayer(playerId) {
			if (isLogin()) {
				uni.navigateTo({
					url: '/packagePages/index/kongjian/index?playerId=' + playerId
				});
			} else {
				toLogin();
			}
		}
	}
};
</script>

<style scoped lang="scss">
.container {
	background-color: #fff;
	height: 100vh;
}

.sell-container {
	display: flex;
	flex-wrap: wrap;
	padding-left: 30rpx;
	padding-right: 30rpx;
	background: transp;
	justify-content: space-between;
	padding-bottom: 30rpx;
	.sell-item {
		width: calc(50% - 12rpx);
		margin-bottom: 20rpx;
	}
}

.search-view-container {
	background-color: #fff;
	height: 100rpx;
	width: 100%;
	display: flex;
	align-items: center;

	.more-btn {
		width: 60rpx;
		height: 50rpx;
		margin-left: auto;
		margin-right: 30rpx;
	}

	.search-view {
		display: flex;
		align-items: center;
		background-color: $main-page-color;
		height: 60rpx;
		border-radius: 30rpx;
		margin-left: 30rpx;
		margin-right: 36rpx;
		width: calc(100% - 130rpx);
		&-icon {
			width: 28rpx;
			height: 28rpx;
			margin-left: 20rpx;
			margin-right: 20rpx;
		}

		&-input {
			font-size: $main-text-size-28;
			width: 80%;
			.placeholder {
				font-size: $main-text-size-28;
				font-family: 'SourceHanSansCN-Regular';
				color: $main-text-color-grey;
			}
		}
	}
}

.empty {
	height: 320rpx;
	line-height: 320rpx;
	text-align: center;
	color: #b5b5b7;
	width: 750rpx;
}

.more-list-wrapper {
	position: fixed;
	z-index: 99;
	top: 0;
	bottom: 0;
	left: 0;
	right: 0;
	background: rgba(0, 0, 0, 0.4);
	overflow: hidden;

	.more-list-view {
		background-color: #fff;
		width: 240rpx;
		height: 197rpx;
		position: fixed;
		top: 120rpx;
		right: 20rpx;
		font-size: 32rpx;
		color: #6c6c6c;
		z-index: 999;
		border-radius: 10rpx;

		&__item {
			display: flex;
			background-color: #fff;
			align-items: center;
			color: #282828;
			height: 99rpx;
			font-size: $main-text-size-30;
			justify-content: center;

			.normal-text {
				color: #282828;
			}

			.selected-text {
				color: $main-text-color-orange-FCC309;
			}
		}

		.arrow {
			border: 40rpx solid transparent;
			border-bottom-color: white;
			top: -60rpx;
			right: 0;
			position: absolute;
		}
	}

	.top-left-right {
		border-top-left-radius: 10rpx;
		border-top-right-radius: 10rpx;
	}

	.bottom-left-right {
		border-bottom-left-radius: 10rpx;
		border-bottom-right-radius: 10rpx;
	}
}

.game-tag-container {
	position: fixed;
	z-index: 999;
	top: 0;
	bottom: 0;
	left: 0;
	right: 0;
	background: rgba(0, 0, 0, 0.4);

	&__body {
		background-color: #fff;
		width: 400rpx;
		height: 100vh;
		overflow-y: auto;
		position: absolute;
		right: 0;
		top: 0;
		font-size: 28rpx;
		animation: mymove 1s 1;

		&-title {
			margin: 20rpx;
			display: block;
		}
	}

	&__tag {
		margin-top: 20rpx;
		display: flex;
		flex-wrap: wrap;
	}

	&__item {
		font-size: 26rpx;
		padding: 10rpx 20rpx 10rpx 20rpx;
		border: 2rpx solid #fcc309;
		color: #fcc309;
		background-color: #fff;
		margin-left: 20rpx;
		margin-top: 20rpx;
		border-radius: 8rpx;
	}

	.selected-game-tag {
		background-color: #fcc309;
		color: #fff;
	}

	&__bottom {
		position: absolute;
		bottom: 20rpx;
		display: flex;
		z-index: 9999;
		font-size: 30rpx;
		width: 100%;
		justify-content: space-between;

		&-reset-btn {
			width: 150rpx;
			height: 70rpx;
			background-color: #dedede;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 8rpx;
			margin-left: 20rpx;
			color: #666;
		}

		&-confirm-btn {
			width: 150rpx;
			height: 70rpx;
			background-color: $main-btn-orange-color;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			border-radius: 8rpx;
			margin-right: 20rpx;
		}
	}
}

@keyframes mymove {
	from {
		right: -100px;
	}

	to {
		right: 0;
	}
}
.hot-container__header {
	display: flex;
	align-items: center;
	margin: 20rpx;
	height: 50rpx;

	&-name {
		margin-top: 10rpx;
		margin-left: 10rpx;
	}

	&-left {
		width: 70rpx;
		height: 70rpx;
	}

	&-icon {
		width: 30rpx;
		height: 30rpx;
		margin-left: auto;
		margin-right: 20rpx;
	}
}
</style>
